$(function() {
    layui.form.verify({
        newpwd: function(value, item) {
            let val = $('[name="old_pwd"]').val()
                // console.log(val)
            if (value === val) {
                return "旧密码不能和原密码一致"
            }
        },
        repwd: function(value, item) {
            let val = $('[name="new_pwd"]').val()
            if (value !== val) {
                return "前后两次密码不一致"
            }
        },

        pwd: [/^\S{6,10}$/, "必须6-15非空字符"]
    })
    $('.layui-form').on('submit', function(e) {
        e.preventDefault()
        let data = $('.layui-form').serialize()
        console.log(data)
        axios.patch('/my/updatepwd', data).then(function({ data: res }) {
            if (res.code === 0) {
                layui.use('layer', function() {
                    var layer = layui.layer;
                    $('[type="reset"]').click()
                    layer.msg('更改成功');
                });

            } else {
                layui.use('layer', function() {
                    var layer = layui.layer;
                    layer.msg('原密码不正确 ');
                });
            }
        })
    })
})